package com.bgIntlgn.client.entity.humanResources;

import java.util.Date;

import yuhuibear.poat.annotations.action.AutoGenerateValue;
import yuhuibear.poat.annotations.action.Macro;
import yuhuibear.poat.annotations.relation.Field;
import yuhuibear.poat.annotations.relation.Table;
import yuhuibear.poat.object.bean.Bean;

/**
 * 员工实体
 * 
 * @author sk-32
 */
@Table(name = "employees", constrain = "")
public class Employee implements Bean {

	@AutoGenerateValue(skipOnNull = true, sqlToGet = "select currval('employees_id_seq')")
	@Field(name = "id", type = "bigserial", constrain = "primary key")
	private Long id;

	/**
	 * 工号 not null.
	 */
	@Field(name = "work_number", type = "varchar(20)", constrain = "unique not null")
	private String workNumber;

	/**
	 * 姓名
	 */
	@Field(name = "name", type = "varchar(50)", constrain = "")
	private String name;

	/**
	 * 性别
	 */
	@Field(name = "male", type = "boolean", constrain = "not null default true")
	private boolean male;

	/**
	 * 所属部门, 为空则没有分配部门
	 */
	@Field(name = "department", type = "int8", constrain = "references departments(id)  on update cascade ")
	private Long department;

	/**
	 * 生日
	 */
	@Field(name = "birthday", type = "date", constrain = "")
	private Date birthday;

	/**
	 * 身份证号
	 */
	@Field(name = "identity_number", type = "varchar(20)", constrain = "not null unique")
	private String identityNumber;

	/**
	 * 入厂时间
	 */
	@Field(name = "in_date", type = "date", constrain = "")
	private Date inDate;

	/**
	 * 职称
	 */
	@Field(name = "rank", type = "varchar(60)", constrain = "")
	private String rank;

	/**
	 * 状态信息 离职,待岗,在岗 [数据字典类型: 员工在岗状态]
	 */
	@Field(name = "status", type = "int8", constrain = "not null references dictionarys(id) on update cascade ")
	private Long status;

	@Macro(name = "employee_name_by_id", depend = "")
	public String employeeNameById() {
		String sql = "create or replace function employee_name_by_id(eid int8) returns text  as $body$ "
				+ "declare 	ename text; "
				+ "begin 	"
				+ "select name into ename from employees where id = eid; 	if not found then return ''; end if; return ename;"
				+ " end $body$ language plpgsql;";
		return sql;
	}

	@Macro(name = "employee_work_number", depend = "")
	public String employeeWorkNumber() {
		String sql = "create or replace function employee_work_number(eid int8) returns text as $BODY$	"
				+ "declare	wn text;begin 	select work_number into wn from employees where id = eid;	return wn;"
				+ "	end;	$BODY$ language 'plpgsql';";
		return sql;
	}

	public Long getStatus() {
		return status;
	}

	public void setStatus(Long status) {
		this.status = status;
	}

	public String getRank() {
		return rank;
	}

	public void setRank(String rank) {
		this.rank = rank;
	}

	public String getWorkNumber() {
		return workNumber;
	}

	public void setWorkNumber(String workNumber) {
		this.workNumber = workNumber;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getIdentityNumber() {
		return identityNumber;
	}

	public void setIdentityNumber(String identityNumber) {
		this.identityNumber = identityNumber;
	}

	public Date getInDate() {
		return inDate;
	}

	public void setInDate(Date inDate) {
		this.inDate = inDate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getDepartment() {
		return department;
	}

	public void setDepartment(Long department) {
		this.department = department;
	}

	public boolean isMale() {
		return male;
	}

	public void setMale(boolean male) {
		this.male = male;
	}

}
